/**
 * Copyright (C), 2015-2018, XXX有限公司
 * FileName: LogController
 * Author:   zhouheng
 * Date:     2018/7/13 11:36
 * Description: 日志管理控制器
 * History:
 * <author>          <time>          <version>          <desc>
 * 作者姓名           修改时间           版本号              描述
 */
package com.hengby.hengcrud.modular.sys.controller;

import com.baomidou.mybatisplus.plugins.Page;
import com.hengby.hengcrud.core.common.factory.PageFactory;
import com.hengby.hengcrud.core.common.status.LogType;
import com.hengby.hengcrud.modular.base.controller.BaseController;
import com.hengby.hengcrud.modular.sys.model.OperationLog;
import com.hengby.hengcrud.modular.sys.service.IOperationLogService;
import com.hengby.hengcrud.modular.sys.warpper.LogWarpper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
import java.util.Map;

/**
 * 〈一句话功能简述〉<br> 
 * 〈日志管理控制器〉
 *
 * @author zhouheng
 * @create 2018/7/13
 * @since 1.0.0
 */
@RequestMapping("/log")
@Controller
public class LogController extends BaseController{

    public static String PREFIX = "/system/log/";

    @Autowired
    private IOperationLogService operationLogService;

    /**
     * 跳转到日志管理的首页
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "log.html";
    }

    /**
     * 查询操作日志列表
     */
    @RequestMapping("/list")
    @ResponseBody
    public Object list(@RequestParam(required = false) String beginTime,
                       @RequestParam(required = false) String endTime,
                       @RequestParam(required = false) String logName,
                       @RequestParam(required = false) Integer logType){

        Page<OperationLog> page = new PageFactory<OperationLog>().defaultPage();

        List<Map<String, Object>> result =
                operationLogService.getOperationLogs(page, beginTime, endTime,
                        logName, LogType.valueOf(logType), page.getOrderByField(), page.isAsc());

        Object object = new LogWarpper(result).wrap();
        page.setRecords((List<OperationLog>) object);
        return super.packForBT(page);

    /*    PageHelper.startPage(page.getCurrent(), page.getSize());
        List<OperationLog> operationLogList = operationLogService.getOperationLogsList(beginTime, endTime,
                logName, LogType.valueOf(logType), page.getOrderByField(), page.isAsc());

        PageInfo<OperationLog> pageInfo = new PageInfo<>(operationLogList);
        return getDataTable(pageInfo);*/
    }

}